package com.wn.controller;

import com.common.entity.PageParam;
import com.common.entity.Rsp;
import com.common.entity.TravelContent;
import com.wn.service.TravelContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("content")
public class TravelContentController {
    @Autowired
    TravelContentService travelContentService;

    @PostMapping("/addOne")
    public Rsp addOne(@RequestBody TravelContent travelContent){
        System.out.println(travelContent.toString());
        return travelContentService.addOne(travelContent);
    }

    @PostMapping("/del")
    public Rsp delcontent(@RequestBody TravelContent travelContent){
        return travelContentService.deleteLogical(travelContent);
    }

    @PostMapping("/updata")
    public Rsp updataContent(@RequestBody TravelContent travelContent){
        return travelContentService.update(travelContent);
    }

    @GetMapping("/selectOne/{textId}")
    public Rsp selectOne(@PathVariable("textId") String textId){
        TravelContent oneById = travelContentService.getOneById(textId);
        if (StringUtils.isEmpty(oneById)){
            return Rsp.fail().msg("查找失败");
        }else {
            return Rsp.success(oneById);
        }
    }

    @PostMapping("/searchSomeByPage")
    public Rsp searchSomeByPage(@RequestBody PageParam<TravelContent> pageParam,
                                @RequestHeader("token")String token){
        return Rsp.success(travelContentService.searchSomeByPage(pageParam));
    }
}
